package com.wc5818.wcComOrder.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wc5818.wcComOrder.entity.WcComOrder;
import com.wc5818.wcComOrder.mapper.WcComOrderMapper;
import com.wc5818.wcComOrder.service.IWcComOrderService;
import com.wc5818.wcSysUser.entity.WcSysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author jobob
 * @since 2020-02-15
 */
@Service
@Primary
public class WcComOrderServiceImpl extends ServiceImpl<WcComOrderMapper, WcComOrder> implements IWcComOrderService {
@Autowired
    private WcComOrderMapper wcComOrderMapper;

    /**
     * 添加订单
     * @param order
     * @return
     */
    @Override
    public Boolean addWCComOrder(WcComOrder order) {
        int num = wcComOrderMapper.addWCComOrder(order);
        if (num != 1) {
            return false;
        } else {
            return true;
        }
    }

    /**
     * 根据父级查询订单
     *
     * @param forbyusername 父级用户名
     * @return
     */
    @Override
    public List<WcComOrder> selectListwcComOrder(String forbyusername,String parentUserId) {
        return wcComOrderMapper.selectListwcComOrder(forbyusername,parentUserId);
    }

    /**
     * 下订单的时候判断是否存在
     *
     * @param userId
     * @return
     */
    @Override
    public Boolean selectWcComOrderUserID(Integer userId) {
        int num = wcComOrderMapper.selectWcComOrderUserID(userId);
        // 等于0代表没下单
        if (num == 0) {
            return true;
        }
        return false;
    }

    /**
     * 查询详情
     *
     * @param userId
     * @return
     */
    @Override
    public WcComOrder getWcComOrderUserID(Integer userId) {
        List<WcComOrder> list = wcComOrderMapper.selectList(new QueryWrapper<WcComOrder>().eq("userId", userId));
        if(list != null && list.size() >0 )
            return list.get(0);

        return null ;
    }

    /**
     * 根据id去改状态
     *
     * @param userId
     * @param status
     * @return
     */
    @Override
    public Boolean updateWcComOrderStatus(Integer userId, String status) {
        int num = wcComOrderMapper.updateWcComOrderStatus(userId,status);
        if (num == 1) {
            return true;
        }
        return false;
    }


}
